/**
 * AJAX anchor navigation
 */
function setAnchor(anchor) {
	location.hash = "#" + anchor;
}

var currentSelectedTreeNodeSpan = null;

function onSelectTreeNode(treeNode) {
	if (currentSelectedTreeNodeSpan) {
		currentSelectedTreeNodeSpan.removeClass("selected");
	}
	var spanTreeNode = $(treeNode.parentNode);
	spanTreeNode.addClass("selected");
	currentSelectedTreeNodeSpan = spanTreeNode;
}

/**
 * Call this on page where you want using RSH library.
 */
function startRsh() {
	window.dhtmlHistory.create({
		blankURL: "<c:url value='/resources/blank.html?' />"
	});
	window.onload = initializeHistory;
}

// AJAX history
function initializeHistory() {
	// initialize RSH
	dhtmlHistory.initialize();

	// add ourselves as a listener for history
	// change events
	dhtmlHistory.addListener(handleHistoryChange);

	// determine our current location so we can
	// initialize ourselves at startup
	var initialLocation = dhtmlHistory.rshIframeID();

	// if no location specified, use the default
	if (initialLocation == null)
		initialLocation = "location1";

	// now initialize our starting UI
	updateUI(initialLocation, null);
}

/*
 * A function that is called whenever the user presses the back or forward
 * buttons. This function will be passed the newLocation, as well as any history
 * data we associated with the location.
 */
function handleHistoryChange(newLocation, historyData) {
	// use the history data to update our UI
	updateUI(newLocation, historyData);
}

/*
 * A simple method that updates our user interface using the new location.
 */
function updateUI(newLocation, historyData) {
	var output = document.getElementById("output");

	// simply display the location and the
	// data
	var historyMessage;
	if (historyData != null)
		historyMessage = historyData.message;

	var message = "New location: " + newLocation + ", history data="
			+ historyMessage;

	output.innerHTML = message;
}

function initializeTree() {
	
}